//#include "StdAfx.h"
#include <pthread.h>
#include "Lock.h"



Lock::Lock(void)
{
	int error=pthread_mutex_init(this->mutex, NULL);
//	if (error==ENOMEM)
//		throw(bad_alloc); TODO implement a proper exception class
}

Lock::~Lock(void)
{
	int error=pthread_mutex_destroy(this->mutex);
//	if (error==EBUSY)
//		thrown(lock_exception); TODO implement a proper exception class
}

void Lock::Enter ()
{
	pthread_mutex_lock(this->mutex);
	return;
}

void Lock::TryEnter()
{
	int error=pthread_mutex_trylock(this->mutex);
	//if(error)
	//	thrown(lock_exception)


	//why doesnt this return anything? shouldnt i return at least
	//whether the lock was acquired or not?
}

void Lock::Release ()
{
	pthread_mutex_unlock(this->mutex);
	return;	
}
